
import 'bootstrap/dist/css/bootstrap.min.css';
require('../css/purchase/detail.less');
require('../css/purchase/index.less');
require('../css/purchase/common.less');
var $ = require('jquery');
import 'bootstrap/dist/js/bootstrap.min.js';

let headerTemplate = require('../view/templateWidget/header.hbs');
let footerTemplate = require('../view/templateWidget/footer.hbs');
let purchInfoTemplate = require('../view/templateWidget/purchInfo.hbs');
let askGoodsTemplate = require('../view/templateWidget/askGoods.hbs');
let addFileTemplate = require('../view/templateWidget/addFile.hbs');
let loginAfterShowTemplate = require('../view/templateWidget/loginAfterShow.hbs');

$('header').html(headerTemplate);
$('footer').html(footerTemplate);

require('../helper/header.js');

var parUrl = window.location.href.split("?")[1];
var nowId = parUrl.split("=")[1];
console.log(nowId);
$.ajax({
    type:"get",
    url:"http://purchasing.mhw001.com/getPurchasingDetail",
    dataType:"json",
    data:{
        purchase_id:nowId,  
    },
    success:function(result){
        console.log(result.data);
        $('.search_keyword').text(result.data.title);   
        $('#purchinfo_box').html(purchInfoTemplate({data: result.data}));
        $("#enquire_goods_box").html(askGoodsTemplate({data: result.data.goods_info}));
        $("#loadFile").html(addFileTemplate({data: result.data}));
        var loadFile = $("#loadFileName").text();
        if(loadFile=="" || loadFile==null || loadFile==undefined){
            $("#loadAccessory").hide();
        }else{
            $("#loadAccessory").show();
        }
        $("#precentCont").html(loginAfterShowTemplate({data: result.data}));
        // 判断登录与否
        var ifLogin = result.data.login;
        var ifInfo_open = result.data.info_open;
        if(ifLogin=="未登录" && ifInfo_open=="登录后公开"){
            $("#precentCont").hide();
            $("#notPrecent").show();
        }else{
            $("#precentCont").show();
            $("#notPrecent").hide();
        }
        var purchaseType = result.data.purchase_type;
        // console.log(purchaseType);
        if(purchaseType=="0"){
            $("#purchase_type").text("现货/标准品");
        }else if(purchaseType=="1"){
            $("#purchase_type").text("加工/定制品");
        }
        $("#delivery_area").text(result.data.delivery);
        var obj = JSON.stringify(result.data.supplier_demand);//将字符串转化为Json格式  
        $("#supply_req").text(obj.replace(/\"/g, "").replace("{", "").replace("}", "")); 
        $("#more_info_inp").text(result.data.explain);
        // 判断类型如果是个人采购隐藏公司名称
        var buyerType = result.data.buyer_type;
        // console.log(buyerType);
        if(buyerType == "企业采购"){
            $(".hideCompanyName").show();
        }else{
            $(".hideCompanyName").hide(); 
        }
        // 判断剩余天数小于1的时候立即报价置灰
        var remainDays = result.data.deadline_days;
        console.log(remainDays);
        if(remainDays<1){
            $(".cont_pict>a").attr('href',"javascript:;");
            $(".cont_pict>a").css('background-color','#eee');
        }
    }
});